// house_pkg/pages/locate/index.ts
//import qqMap from '../../../utils/qqmap.js'

Page({
  /**
   * 页面的初始数据
   */
  data: {
    houseList: [],
    address: '',
    name: '',
  },

  async resetLocation() {
    const { latitude, longitude, address, name } = await wx.chooseLocation()
    this.setData({ address: address, name: name })
    this.getHouseList({ latitude, longitude })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad() {
    const { latitude, longitude } = await wx.getLocation()

    this.setData({
      address: '湖南省长沙市岳麓区含光路504附近',
      name: '八方小区(观沙路)',
    })

    // // 逆地址解析（根据经纬度来获取地址）
    // qqMap.reverseGeocoder({
    //   location: [latitude, longitude].join(','),
    //   success: (res) => {
    //     this.setData({
    //       address: res.result.address,
    //       name: res.result.formatted_addresses.recommend,
    //     })
    //   },
    // })

    this.getHouseList({ latitude, longitude })
  },

  // eslint-disable-next-line no-unused-vars
  getHouseList({ latitude, longitude }) {
    this.setData({
      houseList: [
        {
          id: '17295316374117304139',
          title: '道坡小区',
          address: '湖南省长沙市岳麓区 ',
          tel: '',
          category: '房产小区:住宅区:住宅小区',
          type: 0,
          location: {
            lat: 28.237047,
            lng: 112.931428,
          },
          _distance: 195.72,
          ad_info: {
            adcode: 430104,
            province: '湖南省',
            city: '长沙市',
            district: '岳麓区',
          },
        },
        {
          id: '6894502206399399950',
          title: '瑞和·鹿鸣府',
          address: '湖南省长沙市岳麓区金星北路三段399号',
          tel: '',
          category: '房产小区:住宅区:住宅小区',
          type: 0,
          location: {
            lat: 28.236437,
            lng: 112.932927,
          },
          _distance: 201.26,
          ad_info: {
            adcode: 430104,
            province: '湖南省',
            city: '长沙市',
            district: '岳麓区',
          },
        },
        {
          id: '11164134915557502906',
          title: 'C11双府国际',
          address: '湖南省长沙市岳麓区金星北路499号',
          tel: '',
          category: '房产小区:住宅区:住宅小区',
          type: 0,
          location: {
            lat: 28.233907,
            lng: 112.933205,
          },
          _distance: 238.81,
          ad_info: {
            adcode: 430104,
            province: '湖南省',
            city: '长沙市',
            district: '岳麓区',
          },
        },
        {
          id: '5963685042925905508',
          title: '卓越蔚蓝海岸一期',
          address: '湖南省长沙市岳麓区谷丰北路56号',
          tel: '',
          category: '房产小区:住宅区:住宅小区',
          type: 0,
          location: {
            lat: 28.238322,
            lng: 112.929231,
          },
          _distance: 395.96,
          ad_info: {
            adcode: 430104,
            province: '湖南省',
            city: '长沙市',
            district: '岳麓区',
          },
        },
        {
          id: '16500230183904968050',
          title: '岳府公园邸',
          address: '湖南省长沙市岳麓区含光路与谷丰中路交叉口西80米',
          tel: '',
          category: '房产小区:住宅区:住宅小区',
          type: 0,
          location: {
            lat: 28.236043,
            lng: 112.926877,
          },
          _distance: 445.68,
          ad_info: {
            adcode: 430104,
            province: '湖南省',
            city: '长沙市',
            district: '岳麓区',
          },
        },
      ],
    })
    // qqMap.search({
    //   keyword: '住宅小区', //搜索关键词
    //   location: [latitude, longitude].join(','), //设置周边搜索中心点
    //   page_size: 5,
    //   success: (res) => {
    //     console.log(res, 'res....')

    //     const houseList = res.data.map((v) => ({
    //       id: v.id,
    //       title: v.title,
    //       address: v.address,
    //       _distance: v._distance,
    //       location: v.location
    //     }))

    //     this.setData({ houseList })
    //   },
    // })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
})
